<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <body>
        <ui:composition template="./../Template/generalTemplate.xhtml">
            <ui:define name="content">
                <h:form id="form" prependId="false"  >
                    <p:panel header="Create New Sales Quotation" style="height:495px;">
                        <div style="margin-top:20px;margin-left:50px;margin-right:50px;">
                            <h:outputText value="Select Company" style="font-weight: bold;" /><p:spacer width="10"/>
                            <h:selectOneMenu id="selectOneCompany" required="true" value="#{testGetCompany.selectedCompany.name}"  >
                                <f:selectItem itemLabel="Select Company..." itemValue="" />
                                <f:selectItems value="#{testGetCompany.getCompanyNames()}" var="getCompanies" itemLabel="#{testGetCompany.selectedCompany.name}" itemValue="#{testGetCompany.selectedCompany.name}" />
                                <!-- <f:ajax event="click" execute="@this" render="newEntry"/>-->
                            </h:selectOneMenu>
                            <br /><br />

                            <p:dataTable  id="addLine" value="#{createNewQuotationManagedBean.lineItemList}" var="o">
                                <p:column >
                                    <f:facet name="header">Product Type</f:facet>
                                    #{o.product.productName}
                                </p:column>

                                <p:column>
                                    <f:facet name="header" >Required Quantity (in cases)   </f:facet>
                                    #{o.quantity}
                                </p:column>

                                <p:column>
                                    <f:facet name="header">Action</f:facet>
                                    <h:commandLink value="Delete"   action="#{createNewQuotationManagedBean.deleteLineItem(o)}"/>  

                                </p:column>

                            </p:dataTable>
                            <br />
                            <p:commandButton value="Submit" actionListener="#{createNewQuotationManagedBean.submitQuotation}">
                                <f:attribute name="companyName" value="#{testGetCompany.selectedCompany.name}"/>
                            </p:commandButton>

                            <div style="position:absolute;top:450px;">

                                <p:panel header="Add Item into the Quotation" toggleable="true">
                                    <table>

                                        <td><h:outputText value="Choose Product: "/></td>
                                        <td><h:selectOneMenu id="productType"   required="true" value="#{createNewQuotationManagedBean.productName}" >
                                                <f:selectItem  itemLabel="Please select..." noSelectionOption="true"/>
                                                <f:selectItem   itemValue="Classic Nutri Bar-Nuts" itemLabel="Classic Nutri Bar-Nuts"/>
                                                <f:selectItem   itemValue="Classic Nutri Bar-Fruits" itemLabel="Classic Nutri Bar-Fruits"/>
                                                <f:selectItem   itemValue="Premium Power Bar-Chocolate Nuts" itemLabel="Premium Power Bar-Chocolate Nuts"/>
                                                <f:selectItem  itemValue="Premium Power Bar-Redcurrant Fruits" itemLabel="Premium Power Bar-Redcurrant Fruits"/>
                                            </h:selectOneMenu>
                                        </td>

                                        <td><h:outputText value = "Quantity (in cases)"/></td>
                                        <td><h:inputText     value="#{createNewQuotationManagedBean.lineItem.quantity}" required="true"  validatorMessage="Required quantity should be larger than 0">
                                                <f:validateLongRange minimum="1" />
                                            </h:inputText>
                                        </td>

                                        <td><p:commandButton value="Add" actionListener="#{createNewQuotationManagedBean.addLineItem}" update="addLine statusMessages" ajax="true"    >

                                            </p:commandButton></td>
                                    </table>
                                </p:panel>
                                <p:messages id="statusMessages"/>
                            </div>
                        </div>
                    </p:panel>
                </h:form>
            </ui:define>
        </ui:composition>


    </body>
</html>
